package file;

import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

/**
 * Created by dl
 */
public class ZipDecompress {
	public static void main(String[] args) {
		try (ZipInputStream zipInputStream = new ZipInputStream(ZipDecompress.class.getClassLoader().getResourceAsStream("hello.zip"))) {
			ZipEntry zipEntry;
			byte[] buff = new byte[1024];
			while ((zipEntry = zipInputStream.getNextEntry()) != null) {
				String entryName = zipEntry.getName();
				if (!zipEntry.isDirectory()) {
					StringBuilder sb = new StringBuilder();
					int n;
					while ((n = zipInputStream.read(buff)) > 0) {
						sb.append(new String(buff, 0, n/*charset*/));
					}
					System.out.println("entry file: <" + entryName + ">, content: " + sb.toString());
				} else {
					System.out.println("entry directory: " + entryName);
				}
				zipInputStream.closeEntry();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
